﻿//-----------------------------------------------------------------------
// <copyright file="Copyright.cs" author="Michael Herndon">
//     Copyright (c) Michael Herndon.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Amplify.Twitter
{
	using System.ServiceModel.Security;

	/// <summary>
	/// Manages the users ability to create, destroy and list their favorite 
	/// tweets.
	/// </summary>
	public class FavoriteClient : TwitterClient<IFavoriteClient>, IFavoriteClient 
	{

		/// <summary>
		/// Initializes a new instance of the <see cref="FavoriteClient"/> class.
		/// </summary>
		/// <param name="username">The username.</param>
		/// <param name="password">The password.</param>
		public FavoriteClient(string username, string password)
			: base(username, password)
		{

		}




		#region IFavoriteClient Members

		/// <summary>
		/// Gets an array of the favorites of the current user.
		/// </summary>
		/// <returns>returns an array of <see cref="Amplify.Twitter.Status"/>.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public Status[] GetList()
		{
			return this.GetList(this.Username.ToLower());
		}

		/// <summary>
		/// Gets an array of the favorites of the user specified.
		/// </summary>
		/// <param name="id">The screen name or user id.</param>
		/// <returns>returns an array of <see cref="Amplify.Twitter.Status"/>.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public Status[] GetList(string id)
		{
			try  
			{
				return this.Proxy.GetList(id, 0);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Gets an array of the favorites of the user specified.
		/// </summary>
		/// <param name="id">The screen name or user id.</param>
		/// <param name="page">The number of which page to return.</param>
		/// <returns>returns an array of <see cref="Amplify.Twitter.Status"/>.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public Status[] GetList(string id, int page)
		{
			try
			{
				return this.Proxy.GetList(id, page);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}


		/// <summary>
		/// Destroys a favorite for the specified <see cref="Amplify.Twitter.Status"/> (tweet).
		/// </summary>
		/// <param name="id">The id of the status.</param>
		/// <returns>returns a <see cref="Amplify.Twitter.Status"/> object.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public Status Create(int id)
		{
			return this.Create(id.ToString());
		}

		/// <summary>
		/// Creates a favorite for the specified <see cref="Amplify.Twitter.Status"/> (tweet).
		/// </summary>
		/// <param name="id">The id of the status.</param>
		/// <returns>returns a <see cref="Amplify.Twitter.Status"/> object. </returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public Status Create(string id)
		{
			try 
			{
				return this.Proxy.Create(id);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Destroys a favorite for the specified <see cref="Amplify.Twitter.Status"/> (tweet).
		/// </summary>
		/// <param name="id">The id of the status.</param>
		/// <returns>returns a <see cref="Amplify.Twitter.Status"/> object.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public Status Destroy(int id)
		{
			return this.Destroy(id.ToString());
		}

		/// <summary>
		/// Destroys a favorite for the specified <see cref="Amplify.Twitter.Status"/> (tweet).
		/// </summary>
		/// <param name="id">The id of the status.</param>
		/// <returns>returns a <see cref="Amplify.Twitter.Status"/> object.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public Status Destroy(string id)
		{
			try
			{
				return this.Proxy.Destroy(id);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		#endregion
	}
}
